*******************************************************************************************
* Aarøe, Petersen & Arceneaux 2020
* replication dofile for the results from samples 5 and samples 7
*******************************************************************************************

clear 
set more off

* use the following replication data set
use "Replication dataset for samples 5 and 7.dta", replace

* samples 5 and 7 were collected for the purpose of a different research question.
* Respondents in the two surveys received almost the same questions and therefore  much of the coding below is the same across samples

*******************************************************************************************
* Recodings
*******************************************************************************************

* country dummy
gen denmark =sample
recode denmark (2=0)

* Germ aversion
ta q18_1
sum q18_1
recode q18_3 q18_11 q18_13 (0=6) (1=5) (2=4) (3=3) (4=2) (5=1) (6=0), gen (q18_3rq q18_11rq q18_13rq)
replace q18_11rq = q18_11_dk if q18_11rq ==.
replace q18_13rq = q18_13_dk if q18_13rq ==.

bys denmark: alpha q18_1 q18_7 q18_4 q18_15 q18_9 q18_11rq q18_13rq q18_3rq

egen germ=rmean(q18_1 q18_7 q18_4 q18_15 q18_9 q18_11rq q18_13rq q18_3rq)
gen germ01=germ/6
sum germ01
histogram germ01 

* party preference
** US sample 5 - party ID
gen republican =.
replace republican = 1 if q8 ==2
replace republican = 0 if q8 ==1
ta republican

** Danish data - voting preference
*ranking the parties from left to right on social issues based on voter rating from Danish election study 2015
gen party_dk=. 
drop party_dk
gen party_dk= FT_text 
ta party_dk if party_dk ==16
recode party_dk (7=8) (8=5) (3=7) (1=4) (5=6) (2=3) (4=2) (9=0) (16=1) (6=.) (10=.) (11=.) (12=.) (13=.) (14=.) (15=.)
ta party_dk
gen party_dk01=(party_dk/8)

gen party_preference=.
replace party_preference = party_dk01 if denmark ==1
replace party_preference = republican if denmark ==0


* For the Danish sample generating dummy variable for intention to vote for the Danish People's party versus voting for other parties
gen dummyDPPvote=0
replace dummyDPPvote = 1 if party_dk ==8
replace dummyDPPvote =. if party_dk ==.


* For the Danish sample generating vote choice variable that do not include the Danish People's Party (for analyses of robustness)
* vote choice
recode party_dk (8=.), gen (party_dkNODPP)
gen party_dkNODPP01 = (party_dkNODPP)/7
sum party_dkNODPP01


*gender
gen female = gender == 1
label var female "Female (Yes = 1)"
sum female

*age
label var age "Age (in Years)"

*education
gen edu1= profile_education
recode edu1 (1=1) (2=3) (3=3) (4=2) (5=4) (6=5) (7=6) (8=7)
gen eduDK = (edu1 - 1) / 6
label var eduDK "Education (7-pt: Primary School - Advanced Degree)"
sum eduDK

gen eduUS = (educ - 1) / 5
label var eduUS "Education (6-pt: Primary School - Advanced Degree)"
sum eduUS

egen edu01 = rmean(eduDK eduUS)
sum edu01

* Income
gen house_income = household_income
recode house_income (12=.) (13=.)
gen house_income01=(house_income-1)/10

gen familyincome= faminc
recode familyincome (17=.) (18=.) (31=.) (97=.)

gen familyincome01 = (familyincome-1)/15
ta familyincome01

gen income01=.
replace income01 = house_income01 if denmark ==1
replace income01 = familyincome if denmark ==0

gen race5=race
sum race
recode race5 (1=1) (2=2) (3=3) (4=4) (5=5) (6=5) (7=5) (8=5)
label define race5 1 "white" 2 "black" 3 "Hispanic" 4 "Asian" 5 "Other"
label values race5 race5

*ideology
gen ideoUS=q9_us
gen ideoUS01 =(ideoUS-1)/4
gen ideoDK=q9
gen ideoDK01=(ideoDK/10)
gen ideo01= ideoUS01 if denmark ==0
replace ideo01= ideoDK01 if denmark ==1

* economic and social issue preferences
** the variables are coded so that higher values indicate more conservative orientations 
recode q13_1 q13_2 q13_3 q13_4 q13_5 q14 q14_1 q14_2 q14_3 q14_4 q14_5 q14_6 (6=.)
recode q14_4 q14_5 (1=5) (2=4) (3=3) (4=2) (5=1), gen (q14_4rq q14_5rq)

* social issues
cor q13_1 q13_2 q13_3 q13_4 q13_5 if denmark ==1
cor q13_1 q13_2 q13_3 q13_4 q13_5 if denmark ==0

* q14_6 was not asked in Denmark and scales in the wrong direction therefore not used
* cor q14_1 q14_2 q14_3 q14_4 q14_5 q14_6 if denmark ==0
* cor q14_1 q14_2 q14_3 q14_4 q14_5 if denmark ==1

egen socialissues=rmean(q13_1 q13_2 q13_3 q13_4 q13_5) 
gen socialissues01= (socialissues-1)/4
alpha q13_1 q13_2 q13_3 q13_4 q13_5 if denmark ==0, item
alpha q13_1 q13_2 q13_3 q13_4 q13_5 if denmark ==1, item

egen econissues1DK=rmean(q14_1 q14_2 q14_3 q14_4rq q14_5rq) if denmark ==1
egen econissues1US=rmean(q14_1 q14_2 q14_3 q14_4rq q14_5rq q14_6) if denmark ==0
egen econissues1=rmean(econissues1DK econissues1US)
gen econissues= 6- econissues1
gen econissues01=(econissues-1)/4
alpha q14_1 q14_2 q14_3 q14_4 q14_5 if denmark ==1, item
alpha q14_1 q14_2 q14_3 q14_4 q14_5  q14_6 if denmark ==0, item

sum econissues01
sum socialissues01


* Big five personality traits
recode q12_6 q12_2 q12_8 q12_9 q12_10 (1=7) (2=6) (3=5) (4=4) (5=3) (6=2) (7=1), gen (q12_6rq q12_2rq q12_8rq q12_9rq q12_10rq)

egen extraversion=rmean(q12_1 q12_6rq)
egen agreeableness=rmean(q12_2rq q12_7)
egen conscient=rmean(q12_3 q12_8rq)
egen neuroticism=rmean(q12_4 q12_9rq)
egen openness=rmean(q12_5 q12_10rq)

gen openness01=(openness-1)/6
gen agreeableness01 =(agreeableness-1)/6
gen conscient01=(conscient-1)/6
gen neuroticism01=(neuroticism-1)/6
gen extraversion01=(extraversion-1)/6

* conservatism as measured by the wilson patterson scale

recode q15_1 q15_2 q15_4 q15_10 q15_12 q15_13 q15_15 q15_16 q15_17 q15_19 /*
*/ q15_20 (1=5) (2=4) (3=3) (4=2) (5=1), gen (q15_1rq q15_2rq q15_4rq /*
*/ q15_10rq q15_12rq q15_13rq q15_15rq q15_16rq q15_17rq q15_19rq q15_20rq)

cor q15_1rq q15_2rq q15_3 q15_4rq q15_5 q15_6 q15_7 q15_8 q15_9 q15_10rq q15_11 /*
*/ q15_12rq q15_13rq q15_14 q15_15rq q15_16rq q15_17rq q15_18 q15_19rq q15_20rq if denmark ==0

cor q15_1rq q15_2rq q15_3 q15_4rq q15_5 q15_6 q15_7 q15_8 q15_9 q15_10rq q15_11 /*
*/ q15_12rq q15_13rq q15_14 q15_15rq q15_16rq q15_17rq q15_18 q15_19rq q15_20rq if denmark ==1

bys denmark: alpha q15_1rq q15_2rq q15_3 q15_4rq q15_5 q15_6 q15_7 q15_8 q15_9 q15_10rq q15_11 /*
*/ q15_12rq q15_13rq q15_14 q15_15rq q15_16rq q15_17rq q15_18 q15_19rq q15_20rq

egen WPideo=rmean(q15_1rq q15_2rq q15_3 q15_4rq q15_5 q15_6 q15_7 q15_8 q15_9 q15_10rq q15_11 /*
*/ q15_12rq q15_13rq q15_14 q15_15rq q15_16rq q15_17rq q15_18 q15_19rq q15_20rq)

gen WPideo01=(WPideo-1)/4
bys denmark: sum WPideo01

pwcorr WPideo01 socialissues01 econissues01, sig

pwcorr WPideo01 socialissues01 econissues01 if denmark ==0, sig
pwcorr WPideo01 socialissues01 econissues01 if denmark ==1, sig

pwcorr ideo01 socialissues01 econissues01 if denmark ==0, sig
pwcorr ideo01 socialissues01 econissues01 if denmark ==1, sig

******************************************************************
* Analysis and descriptive statistics 
********************************************************************

* sample descriptives 
sum female if denmark ==1
sum age if denmark ==1
ta eduDK if denmark ==1
ta  household_income if denmark ==1


sum female if denmark ==0
sum age if denmark ==0
ta eduUS if denmark ==0
ta  faminc if denmark ==0
ta race5 if denmark ==0

bys denmark: sum germ01

bys denmark: sum party_preference 
ta party_preference if denmark ==0 

bys denmark: sum ideo01

* Average marginal effects for Figure 1 in the main text for the Danish sample 7
* The average marginal effects are also reported on Online Appendix A3.1.1
* the estimates were included in the dataset for the metaanalysis of effects of pathogen avoidance motivation on party preferences
reg party_preference female germ01 income01 edu01 age /*
*/ openness01 agreeableness01 conscient01 neuroticism01 extraversion01 if denmark ==1
margins, dydx(germ01 income01 edu01 openness01 conscient01 agreeableness01) level(90)

* analysis for Table A13, models 1-3, for the Danish sample 7 
eststo: reg party_preference germ01 female income01 edu01 age /*
*/ openness01 conscient01 extraversion01 agreeableness01 neuroticism01  if denmark ==1
eststo: reg party_dkNODPP01 germ01 female income01 edu01 age /*
*/ openness01 agreeableness01 conscient01 neuroticism01 extraversion01 if denmark ==1, level (90)
eststo: ologit party_preference  germ01 female income01 edu01 age /*
*/ openness01 agreeableness01 conscient01 neuroticism01 extraversion01 if denmark ==1
esttab, b (%5.2f) se(%5.2f), using part_3.rtf,replace onecell star(* 0.10 ** 0.02 *** 0.002) wide constant ar2
eststo clear

* calculating by hand the z-score for the difference between the coefficient for the effect of pathogen avoidance motivation on vote intentions in the models with (table A13, M1) and without the Danish People's Party (atble A13, M2) (for the note below Table A13)
*  z-score = (0.1413944 - 0.1782019)/sqrt(0.05905+0.0550907)
* z = -0.108947195. This corresponds to a one-sided p-value of 0.457 (calculated using https://www.socscistatistics.com/pvalues/normaldistribution.aspx) 


* Average marginal effects for Figure 1 in the main text for the US sample 5
* The average marginal effects are also reported on Online Appendix A3.1.1
* the estimates were included in the dataset for the metaanalysis of effects of pathogen avoidance motivation on party preferences
probit party_preference germ01 female income01 edu01 age i.race5 /*
*/openness01 agreeableness01 conscient01 neuroticism01 extraversion01 if denmark ==0
margins, dydx(germ01 income01 edu01 openness01 conscient01 agreeableness01) level(90) post 


* results for Table A11 for the US sample 5
eststo: probit party_preference germ01 income01 female edu01 age i.race5 /*
*/ openness01 agreeableness01 conscient01  extraversion01 neuroticism01 if denmark ==0
esttab, b (%5.2f) se(%5.2f) , using part_3.rtf,replace onecell star(* 0.10 ** 0.02 *** 0.002) wide constant ar2
eststo clear

* analyses of robustness for figure 2 in the main text reported in the online appendix A3.2
* the estimates from the regression analysis were included in the dataset for the meta-analysis of effects of pathogen avoidance motivation on party preferences 

reg party_preference female germ01 income01 edu01 age /*
*/ openness01 agreeableness01 conscient01 neuroticism01 extraversion01 if denmark ==1

gen miss=e(sample)
ta miss if denmark ==1

reg party_preference female income01 edu01 age /*
*/ openness01 conscient01 agreeableness01 neuroticism01 extraversion01 if denmark ==1 & miss ==1
margins, dydx(income01 edu01 openness01 conscient01 agreeableness01) level(90)

reg party_preference female income01 edu01 age /*
*/  if denmark ==1 & miss ==1
margins, dydx(income01 edu01) level(90)


reg party_preference germ01 female income01 edu01 age i.race5 /*
*/ openness01 agreeableness01 conscient01 neuroticism01 extraversion01 if denmark ==0 
gen miss2=e(sample)

reg party_preference female income01 edu01 age i.race5 /*
*/ openness01 conscient01 agreeableness01 neuroticism01 extraversion01 if denmark ==0 & miss2 ==1
margins, dydx(income01 edu01 openness01 conscient01 agreeableness01) level(90)


reg party_preference female income01 edu01 age i.race5 /*
*/  if denmark ==0 & miss2 ==1
margins, dydx(income01 edu01) level(90)


reg party_preference germ01 female germ01 income01 edu01 age /*
*/ openness01 agreeableness01 conscient01 neuroticism01 extraversion01 if denmark ==1

gen miss3=e(sample)
ta miss if denmark ==1


reg party_preference germ01 female income01 edu01 age /*
*/  if denmark ==1 & miss3 ==1
margins, dydx(germ01) level(90)

reg party_preference germ01 female income01 edu01 age i.race5 /*
*/ openness01 agreeableness01 conscient01 neuroticism01 extraversion01 if denmark ==0 
gen miss4=e(sample)

reg party_preference germ01 female income01 edu01 age i.race5 /*
*/  if denmark ==0 & miss4 ==1
margins, dydx(germ01) level(90)



*Analyses for Online Appendix A3.3. 
* the estimates were included in the dataset for the meta analysis for the effect of pathogen avoidance motivation on ideological preferences

* Danish Sample 7
eststo: reg socialissues01 germ01 edu01 income01 female age /*
*/ openness01 agreeableness01 conscient01 neuroticism01 extraversion01 if denmark ==1
margins, dydx(germ01) level(90)

eststo: reg econissues01 germ01 edu01 income01 female age /*
*/ openness01 agreeableness01 conscient01 neuroticism01 extraversion01 if denmark ==1
margins, dydx(germ01) level(90)

eststo: reg ideo01 germ01 edu01 income01 female age /*
*/ openness01 agreeableness01 conscient01 neuroticism01 extraversion01 if denmark ==1
margins, dydx(germ01) level(90)

eststo: reg WPideo01 germ01 edu01 income01 female age /*
*/ openness01 agreeableness01 conscient01 neuroticism01 extraversion01 if denmark ==1
margins, dydx(germ01) level(90)

esttab, b (%5.2f) se(%5.2f) , using part_3.rtf,replace onecell star(* 0.10 ** 0.02 *** 0.002) wide constant r2
eststo clear


* US Sample 5
eststo: reg socialissues01 germ01 edu01 income01 female age i.race5 /*
*/ openness01 agreeableness01 conscient01 neuroticism01 extraversion01 if denmark ==0
margins, dydx(germ01) level(90)

eststo: reg econissues01 germ01 edu01 income01 female age i.race5 /*
*/ openness01 agreeableness01 conscient01 neuroticism01 extraversion01 if denmark ==0
margins, dydx(germ01) level(90)

eststo: reg ideo01 germ01 edu01 income01 female age i.race5 /*
*/ openness01 agreeableness01 conscient01 neuroticism01 extraversion01 if denmark ==0
margins, dydx(germ01) level(90)

eststo: reg WPideo01 germ01 edu01 income01 female age i.race5 /*
*/ openness01 agreeableness01 conscient01 neuroticism01 extraversion01 if denmark ==0
margins, dydx(germ01) level(90)

** Decomposition of the correlation between pathogen avoidance motivation and partisanship into a direct and an indirect pathway via social and economic issue preferences

* Danish sample 7

* Table 2 in the main text for the Danish Sample 7
keep if denmark ==1

eststo clear
eststo: khb reg party_preference germ01 || socialissues01 econissues01, /*
*/ concomitant(edu01 income01 female age openness01 agreeableness01 conscient01 neuroticism01 extraversion01) /*
*/disentangle summary 
esttab, b(%5.2f) se(%5.2f), using part_2.rtf, replace onecell star(* 0.1 ** 0.02 *** 0.002) wide constant r2 pr2
eststo clear

* Analyses of robustness using the ACME framework reported in Table A16, A3.3.1 for the Danish sample 7
medeff (regress socialissues01 germ01  edu01 income01 female age openness01 agreeableness01 conscient01 neuroticism01 extraversion01) /*
*/(regress party_preference socialissues01 germ01  edu01 income01 female age openness01 agreeableness01 /*
*/conscient01 neuroticism01 extraversion01) /*
*/, mediate (socialissues01) treat(germ01) sims(1000) seed(1) level (90)

medsens (regress socialissues01 germ01  edu01 income01 female age openness01 agreeableness01 /*
*/conscient01 neuroticism01 extraversion01) /*
*/ (regress party_preference socialissues01 germ01  edu01 income01 female age openness01 agreeableness01 /*
*/conscient01 neuroticism01 extraversion01) /*
*/, mediate (socialissues01) treat(germ01) sims(1000) level (90)


medeff (regress econissues01 germ01  edu01 income01 female age openness01 agreeableness01 conscient01 neuroticism01 extraversion01) /*
*/(regress party_preference econissues01 germ01  edu01 income01 female age openness01 agreeableness01 /*
*/conscient01 neuroticism01 extraversion01) /*
*/, mediate (econissues01) treat(germ01) sims(1000) seed(1) level (90)

medsens (regress econissues01 germ01  edu01 income01 female age openness01 agreeableness01 /*
*/conscient01 neuroticism01 extraversion01) /*
*/ (regress party_preference econissues01 germ01  edu01 income01 female age openness01 agreeableness01 /*
*/conscient01 neuroticism01 extraversion01) /*
*/, mediate (econissues01) treat(germ01) sims(1000) level (90)


* A3.3.2 Analyses of robustness using alternative measures of social issues in  the Danish sample 7
* Results for Table A17 in the Danish sample 7
eststo clear
eststo: khb reg party_preference germ01 || WPideo01, /*
*/ concomitant(edu01 income01 female age openness01 agreeableness01 conscient01 neuroticism01 extraversion01) /*
*/disentangle summary 
esttab, b(%5.2f) se(%5.2f), using part_2.rtf, replace onecell star(* 0.1 ** 0.02 *** 0.002) wide constant r2 pr2
eststo clear


* Results for Table A19 in the Danish sample 7
eststo clear
eststo: khb reg party_preference germ01 || ideo01, /*
*/ concomitant(edu01 income01 female age openness01 agreeableness01 conscient01 neuroticism01 extraversion01) /*
*/disentangle summary 
esttab, b(%5.2f) se(%5.2f), using part_2.rtf, replace onecell star(* 0.1 ** 0.02 *** 0.002) wide constant r2 pr2
eststo clear



* us data sample 5
clear
*run all recodings 

keep if denmark ==0

* Table 2 in the main text for the US Sample 5
eststo clear
eststo: khb probit party_preference germ01 || socialissues01 econissues01, /*
*/ concomitant(edu01 income01 female age i.race5 openness01 agreeableness01 conscient01 neuroticism01 extraversion01) /*
*/disentangle summary 
esttab, b(%5.2f) se(%5.2f), using part_2.rtf, replace onecell star(* 0.1 ** 0.02 *** 0.002) wide constant r2 pr2
eststo clear
* the statistical sigificance of the coefficients for the indirect effect via social issues and economic issues reported in Table 2 were calculated manually (using the coefficients and standard errors from the models above) as this not part of the standard stata output. See the excel spreadsheet "calculation of statistical significance for indirect effects via social and economic issues Table 2, sample 4"


* Analyses of robustness using the ACME framework reported in Table A16, A3.3.1 for the US sample 5
tab race5, gen(d)

medeff (regress socialissues01 germ01  edu01 income01 female age openness01 agreeableness01 conscient01 neuroticism01 extraversion01 d1 d2 d3 d4) /*
*/(probit party_preference socialissues01 germ01  edu01 income01 female age openness01 agreeableness01 /*
*/conscient01 neuroticism01 extraversion01 d1 d2 d3 d4 ) /*
*/, mediate (socialissues01) treat(germ01) sims(1000) seed(1) level (90)

medsens (regress socialissues01 germ01  edu01 income01 female age openness01 agreeableness01 /*
*/conscient01 neuroticism01 extraversion01 d1 d2 d3 d4) /*
*/ (probit party_preference socialissues01 germ01  edu01 income01 female age openness01 agreeableness01 /*
*/conscient01 neuroticism01 extraversion01 d1 d2 d3 d4) /*
*/, mediate (socialissues01) treat(germ01) sims(1000) level (90)


medeff (regress econissues01 germ01  edu01 income01 female age openness01 agreeableness01 conscient01 neuroticism01 extraversion01 d1 d2 d3 d4) /*
*/(probit party_preference econissues01 germ01  edu01 income01 female age openness01 agreeableness01 /*
*/conscient01 neuroticism01 extraversion01 d1 d2 d3 d4 ) /*
*/, mediate (econissues01) treat(germ01) sims(1000) seed(1) level (90)

medsens (regress econissues01 germ01  edu01 income01 female age openness01 agreeableness01 /*
*/conscient01 neuroticism01 extraversion01 d1 d2 d3 d4) /*
*/ (probit party_preference econissues01 germ01  edu01 income01 female age openness01 agreeableness01 /*
*/conscient01 neuroticism01 extraversion01 d1 d2 d3 d4) /*
*/, mediate (econissues01) treat(germ01) sims(1000) level (90)


* A3.3.2 Analyses of robustness using alternative measures of social issues in the US Sample 5
* Results for Table A17 in the US sample 5
eststo clear
eststo: khb probit party_preference germ01 || WPideo01, /*
*/ concomitant(edu01 income01 female age i.race5 openness01 agreeableness01 conscient01 neuroticism01 extraversion01) /*
*/disentangle summary 
esttab, b(%5.2f) se(%5.2f), using part_2.rtf, replace onecell star(* 0.1 ** 0.02 *** 0.002) wide constant r2 pr2
eststo clear


* Results for Table A18 in the US sample 5
eststo clear
eststo: khb probit party_preference germ01 || ideo01, /*
*/ concomitant(edu01 income01 female age i.race5 openness01 agreeableness01 conscient01 neuroticism01 extraversion01) /*
*/disentangle summary 
esttab, b(%5.2f) se(%5.2f), using part_2.rtf, replace onecell star(* 0.1 ** 0.02 *** 0.002) wide constant r2 pr2
eststo clear




